### Initialise compiler and linker flags ###

IF( AJ_PLATFORM_WINDOWS )
	INCLUDE( AJCompiler_msvc )
ELSEIF( AJ_PLATFORM_MAC )
	INCLUDE( AJCompiler_clang )
ELSE()
	# TODO: Add compiler and linker support for other compilers/platforms here
	# TODO: Split into per compiler files for the AJ_* compiler and linker settings
	MESSAGE( FATAL " Unsupported compiler " )
ENDIF()

# Define a _${_CONFIG_NAME} preprocessor variable (e.g. _DEBUG)
SET_PROPERTY( DIRECTORY APPEND PROPERTY
	COMPILE_DEFINITIONS $<$<CONFIG:DEBUG>:"_DEBUG"> )
SET_PROPERTY( DIRECTORY APPEND PROPERTY
	COMPILE_DEFINITIONS $<$<CONFIG:RELEASE>:"_RELEASE"> )

### Overide all CMake compile and link flags
### Don't modify these, modify the AJ versions

FUNCTION( _AJ_SET_LIST CACHENAME VALUE )
	# replace ';' separated list items with ' '
	STRING( REPLACE ";" " " TEMPVAR "${VALUE}" )
	SET( "${CACHENAME}" "${TEMPVAR}" ${ARGN} )
ENDFUNCTION()

_AJ_SET_LIST( CMAKE_C_FLAGS "${AJ_C_FLAGS}"
	CACHE STRING "Flags used by the compiler for all build types" FORCE )
_AJ_SET_LIST( CMAKE_C_FLAGS_DEBUG "${AJ_C_FLAGS_DEBUG}"
	CACHE STRING "Flags used by the compiler for all Debug builds" FORCE )
_AJ_SET_LIST( CMAKE_C_FLAGS_RELEASE "${AJ_C_FLAGS_RELEASE}"
	CACHE STRING "Flags used by the compiler for all Release builds" FORCE )

_AJ_SET_LIST( CMAKE_CXX_FLAGS "${AJ_CXX_FLAGS}"
	CACHE STRING "Flags used by the compiler for all build types" FORCE )
_AJ_SET_LIST( CMAKE_CXX_FLAGS_DEBUG "${AJ_CXX_FLAGS_DEBUG}"
	CACHE STRING "Flags used by the compiler for all Debug builds" FORCE )
_AJ_SET_LIST( CMAKE_CXX_FLAGS_RELEASE "${AJ_CXX_FLAGS_RELEASE}"
	CACHE STRING "Flags used by the compiler for all Release builds" FORCE )

_AJ_SET_LIST( CMAKE_EXE_LINKER_FLAGS "${AJ_EXE_LINKER_FLAGS}"
	CACHE STRING "Flags used by the linker" FORCE )
_AJ_SET_LIST( CMAKE_EXE_LINKER_FLAGS_DEBUG "${AJ_EXE_LINKER_FLAGS_DEBUG}"
	CACHE STRING "Flags used by the linker for Debug builds" FORCE )
_AJ_SET_LIST( CMAKE_EXE_LINKER_FLAGS_RELEASE "${AJ_EXE_LINKER_FLAGS_RELEASE}"
	CACHE STRING "Flags used by the linker for Release builds" FORCE )

_AJ_SET_LIST( CMAKE_MODULE_LINKER_FLAGS "${AJ_MODULE_LINKER_FLAGS}"
	CACHE STRING "Flags used by the linker for the creation of modules" FORCE )
_AJ_SET_LIST( CMAKE_MODULE_LINKER_FLAGS_DEBUG "${AJ_MODULE_LINKER_FLAGS_DEBUG}"
	CACHE STRING "Flags used by the linker for Debug builds" FORCE )
_AJ_SET_LIST( CMAKE_MODULE_LINKER_FLAGS_RELEASE "${AJ_MODULE_LINKER_FLAGS_RELEASE}"
	CACHE STRING "Flags used by the linker for Release builds" FORCE )

_AJ_SET_LIST( CMAKE_SHARED_LINKER_FLAGS "${AJ_SHARED_LINKER_FLAGS}"
	CACHE STRING "Flags used by the linker for the creation of dll's" FORCE )
_AJ_SET_LIST( CMAKE_SHARED_LINKER_FLAGS_DEBUG "${AJ_SHARED_LINKER_FLAGS_DEBUG}"
	CACHE STRING "Flags used by the linker for Debug builds" FORCE )
_AJ_SET_LIST( CMAKE_SHARED_LINKER_FLAGS_RELEASE "${AJ_SHARED_LINKER_FLAGS_RELEASE}"
	CACHE STRING "Flags used by the linker for Release builds" FORCE )

_AJ_SET_LIST( CMAKE_STATIC_LINKER_FLAGS "${AJ_STATIC_LINKER_FLAGS}"
	CACHE STRING "Flags used by the linker for the creation of static libraries" FORCE )
_AJ_SET_LIST( CMAKE_STATIC_LINKER_FLAGS_DEBUG "${AJ_STATIC_LINKER_FLAGS_DEBUG}"
	CACHE STRING "Flags used by the linker for Debug builds" FORCE )
_AJ_SET_LIST( CMAKE_STATIC_LINKER_FLAGS_RELEASE "${AJ_STATIC_LINKER_FLAGS_RELEASE}"
	CACHE STRING "Flags used by the linker for Release builds" FORCE )

_AJ_SET_LIST( CMAKE_RC_FLAGS "${BW_RC_FLAGS}"
	CACHE STRING "Flags used by the resource compiler" FORCE )

IF( CMAKE_VERBOSE )
	MESSAGE( STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}" )
	MESSAGE( STATUS "CMAKE_C_FLAGS_DEBUG: ${CMAKE_C_FLAGS_DEBUG}" )
	MESSAGE( STATUS "CMAKE_C_FLAGS_RELEASE: ${CMAKE_C_FLAGS_RELEASE}" )
	MESSAGE( STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}" )
	MESSAGE( STATUS "CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}" )
	MESSAGE( STATUS "CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}" )
	MESSAGE( STATUS "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}" )
	MESSAGE( STATUS "CMAKE_EXE_LINKER_FLAGS_DEBUG: ${CMAKE_EXE_LINKER_FLAGS_DEBUG}" )
	MESSAGE( STATUS "CMAKE_EXE_LINKER_FLAGS_RELEASE: ${CMAKE_EXE_LINKER_FLAGS_RELEASE}" )
	MESSAGE( STATUS "CMAKE_MODULE_LINKER_FLAGS: ${CMAKE_MODULE_LINKER_FLAGS}" )
	MESSAGE( STATUS "CMAKE_MODULE_LINKER_FLAGS_DEBUG: ${CMAKE_MODULE_LINKER_FLAGS_DEBUG}" )
	MESSAGE( STATUS "CMAKE_MODULE_LINKER_FLAGS_RELEASE: ${CMAKE_MODULE_LINKER_FLAGS_RELEASE}" )
	MESSAGE( STATUS "CMAKE_SHARED_LINKER_FLAGS: ${CMAKE_SHARED_LINKER_FLAGS}" )
	MESSAGE( STATUS "CMAKE_SHARED_LINKER_FLAGS_DEBUG: ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" )
	MESSAGE( STATUS "CMAKE_SHARED_LINKER_FLAGS_RELEASE: ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}" )
	MESSAGE( STATUS "CMAKE_STATIC_LINKER_FLAGS: ${CMAKE_STATIC_LINKER_FLAGS}" )
	MESSAGE( STATUS "CMAKE_STATIC_LINKER_FLAGS_DEBUG: ${CMAKE_STATIC_LINKER_FLAGS_DEBUG}" )
	MESSAGE( STATUS "CMAKE_STATIC_LINKER_FLAGS_RELEASE: ${CMAKE_STATIC_LINKER_FLAGS_RELEASE}" )
	MESSAGE( STATUS "CMAKE_RC_FLAGS: ${CMAKE_RC_FLAGS}" )
ENDIF()

MARK_AS_ADVANCED(
	CMAKE_C_FLAGS_DEBUG
	CMAKE_C_FLAGS_RELEASE
	CMAKE_CXX_FLAGS_DEBUG
	CMAKE_CXX_FLAGS_RELEASE
	CMAKE_EXE_LINKER_FLAGS_DEBUG
	CMAKE_EXE_LINKER_FLAGS_RELEASE
	CMAKE_MODULE_LINKER_FLAGS_DEBUG
	CMAKE_MODULE_LINKER_FLAGS_RELEASE
	CMAKE_SHARED_LINKER_FLAGS_DEBUG
	CMAKE_SHARED_LINKER_FLAGS_RELEASE
	CMAKE_STATIC_LINKER_FLAGS_DEBUG
	CMAKE_STATIC_LINKER_FLAGS_RELEASE
	CMAKE_RC_FLAGS
)
